package com.ls.mysql.quartz.config;

import com.ls.mysql.quartz.scheduleTask.MyTask1;
import org.quartz.*;

/**
 * @Author Maple.Chen
 * @Description 一个自动注册的测试类
 * 比较麻烦且不够灵活，无法做到动态任务调度
 * 不推荐，所以我写了SchedulerService来代替这个类
 * @Date 10:19 2020/5/29
 **/
//@Configuration
public class QuartzConfig {
    //    @Bean
    public JobDetail myJobDetail() {
        JobDetail jobDetail = JobBuilder.newJob(MyTask1.class)
                .withIdentity("myJob1", "myJobGroup1")
                //JobDataMap可以给任务execute传递参数
                .usingJobData("job_param", "job_param1")
                .storeDurably()
                .build();
        return jobDetail;
    }

    //    @Bean
    public Trigger myTrigger() {
        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(myJobDetail())
                .withIdentity("myTrigger1", "myTriggerGroup1")
                .usingJobData("job_trigger_param", "job_trigger_param1")
                .startNow()
                //.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever())
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ? 2020"))
                .build();
        return trigger;
    }
}
